<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="98px"
    >
      <el-form-item label="索引名称" prop="dict_name">
        <el-input
          v-model="queryParams.dict_name"
          placeholder="请输入模板名称"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="模板主键" prop="template_id">
        <el-input
          v-model="queryParams.template_id"
          placeholder="请输入"
          clearable
          size="small"
        />
      </el-form-item>
    </el-form>
    <el-button size="small" type="primary" @click="clearFile()"
      >入库es</el-button
    >

    <el-table v-loading="loading" :data="jobList">
      <el-table-column label="模板名称" align="center" prop="dict_name" />
      <el-table-column label="模板主键" align="center" prop="template_id" />
      <el-table-column label="模板数量" align="center" prop="num" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span>{{ map[scope.row.status] }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getList, rukuEs } from '@/api/dataCommit/dataCommit'

export default {
  name: 'Job',
  components: {},
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      person: '',
      // 任务主表格数据
      jobList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      params: {
        indexName: '',
        templateId: ''
      },
      arr: [
        { key: 111, value: 'value1' },
        { key: 333, value: 'value2' },
        { key: 5555, value: 'value3' }
      ],
      jobGroupOptions: [],
      uploadFileUrl: process.env.VUE_APP_BASE_API + '/job/job/bulkInsertEs', // 上传的地址
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dict_name: undefined,
        template_id: undefined
      },
      // 表单参数
      form: {}
    }
  },
  computed: {
    // 任务状态,1:待认领 2:待打标 3:待审核 4:审核通过 5:入库成功'
    map() {
      return {
        1: '待认领',
        2: '待打标',
        3: '待审核',
        4: '审核通过',
        5: '入库成功'
      }
    }
  },
  created() {
    this.getList()
    this.getPerson()
    // const result = Object.assign(
    //   ...this.arr.map(el => ({ [el.key]: el.value }))
    // )
    // console.log(result, ...this.arr, this.arr)
    var obj = {}
    this.arr.forEach(function(item) {
      obj[item.key] = item.value
    })
    console.log(obj)
  },
  methods: {
    clearFile() {
      rukuEs({
        templateId: parseInt(this.queryParams.template_id),
        indexName: this.queryParams.dict_name
        // eslint-disable-next-line no-undef
      }).then((res = {}))
    },

    getPerson() {
      // getJobPerson({ roleIds: 100 }).then(res => {
      //   this.jobGroupOptions = res.rows
      // })
    },

    handleChange(value) {
      console.log(value)
      this.person = value
    },
    /** 查询任务主列表 */
    getList() {
      this.loading = true
      getList(this.queryParams).then(response => {
        console.log(response)
        this.jobList = response.rows
        this.total = response.total
        this.loading = false
      })
    }
  }
}
</script>
